//
//  LevelScene.h
//  HelloCpp
//
//  Created by apple  on 13-6-15.
//
//

#ifndef __XIAOLIAN__LevelScene__
#define __XIAOLIAN__LevelScene__


#include "cocos2d.h"
#include "Box2D/Box2D.h"

USING_NS_CC;

class QueryCallback : public b2QueryCallback
{
public:
    virtual ~QueryCallback() {}
    
    /// Called for each fixture found in the query AABB.
    /// @return false to terminate the query.
    virtual bool ReportFixture(b2Fixture* fixture);
};


class LevelScene : public CCLayer
{
public:
    LevelScene():m_pb2World(0), m_nLevel(0), m_bSuccess(false), m_bFailed(false), m_bChecking(false), m_nTimer(5), m_clockSoundID(-1){}
    virtual ~LevelScene();
    
    static CCScene* create(int nLevel);
    
    virtual void onEnter();
    virtual void onExit();
    
    bool init(int nLevel);
	bool initWithFile(const char* levelFile);
    
    virtual void update(float dt);
    
    void menuItemClick(CCObject* sender);
    
    virtual void ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent);
    virtual void ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent);
    virtual void ccTouchesEnded(CCSet *pTouches, CCEvent *pEvent);
    
	virtual void successed();
	virtual void failed();
    void updateBox2D(float dt);
    void tick(float dt);
    
    void checking(float dt);
protected:
    b2World*    m_pb2World;
    int         m_nLevel;
    
    float       m_beginDistance;
    bool        m_bSuccess;
    bool        m_bFailed;
    bool        m_bChecking;
    int         m_nTimer;
    int         m_clockSoundID;
    
    CCNode*     m_pLevelNode;
    QueryCallback m_callback;
};

#endif /* defined(__XIAOLIAN__LevelScene__) */
